package com.newhis.thread;

import org.slf4j.MDC;

import java.util.UUID;

public class TraceIdUtil {
    public static final String TRACE_ID = "traceId";
    public static final String CLIENT_IP = "clientIp";
    public static String getTraceId() {
        String traceId =(String) MDC.get(TRACE_ID);
        return traceId == null ? "" : traceId;
    }
    public static void setTraceId(String traceId) {
        MDC.put(TRACE_ID,traceId);
    }
    public static void setClientIp(String ip) {
        MDC.put(CLIENT_IP,ip);
    }
    public static void remove() {
        MDC.remove(TRACE_ID);
        MDC.remove(CLIENT_IP);
    }
    public static void clear() {
        MDC.clear();
    }
    public static String generateTraceId() {
        return UUID.randomUUID().toString().replace("-", "");
    }
}
